home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14663 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.3 KB  |  156 lines

  1. Newsgroups: comp.lang.c++
  2. Path: nntp.coast.net!torn!sis!apollo!gerrity
  3. From: gerrity@apollo.sheridanc.on.ca (Jason Gerrity)
  4. Subject: Is there a better way?
  5. Message-ID: <Dp6xn8.BvA@relay.sheridanc.on.ca>
  6. Sender: news@relay.sheridanc.on.ca (USENET News System)
  7. Nntp-Posting-Host: apollo.sheridanc.on.ca
  8. Organization: Sheridan College, Ont., Canada
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. Date: Mon, 1 Apr 1996 15:57:08 GMT
  11.  
  12. Hello All,
  13.  
  14. I'm working on a piece of code that is giving me a headache,  
  15. could some kind person point out a better or correct way of doing
  16. this?
  17.  
  18. I'm parsing an input line using strtok and have spaces as the
  19. delimeter.  I then need to check to see if certain 'words' have
  20. been inputed and then grab everything after the 'word' and use
  21. whats grabbed as a variable.
  22.  
  23. Problem is that when using strtok, I use a while loop so as
  24. long as the strtok is not NULL then the loop continues, unfortunatley
  25. the strtok gets set to NULL on the first pass..here's my code so far:
  26.  
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <string.h>
  31.  
  32.  main()
  33.    {
  34.  
  35.  
  36.  
  37.  
  38.     int Counter;
  39.     int Failure;
  40.     int GenericAccount;
  41.     int GenericAccountErase;
  42.     int LinkOption;
  43.     int ServerOption;
  44.     int SetUIDOption;
  45.     int checksetuid;
  46.     int checkLinkOptionPath;
  47.     int checkServerOptionPath;
  48.     int checknoerase;
  49.     char *Login;
  50.     char *pLogin
  51.     char ServerOptionPath[60];
  52.     char LinkOptionPath[20];
  53.     char *LogTemp;
  54.  
  55.     memset(ServerOptionPath,0 ,60);
  56.     memset(LinkOptionPath, 0, 20);
  57.  
  58.     for (Counter = 0; Counter < 3; Counter++)
  59.     {
  60.         printf("\r\nLogin: ");
  61.  
  62.         gets(Login);
  63.         pLogin = strtok(Login, " ");
  64.         while(pLogin)
  65.         {
  66.              char *ptr;
  67.              strcpy(ptr, pLogin);
  68.  
  69.              LogTemp = strstr(ptr, "check1");
  70.              if (LogTemp)
  71.             {
  72.                 checksetuid =1;
  73.                 SetUIDOption = 1;
  74.                 printf("\r\n%s option recognized", LogTemp);
  75.             }
  76.             else
  77.             {
  78.                 if (checksetuid !=1)
  79.                 SetUIDOption = 0;
  80.             }
  81.  
  82.             LogTemp = strstr(ptr, "check2");
  83.             if (LogTemp)
  84.             {
  85.                 checknoerase = 1;
  86.                 GenericAccountErase = 0;
  87.                 printf("\r\n%s option recognized", LogTemp);
  88.             }
  89.             else
  90.             {
  91.                 if (checknoerase !=1)
  92.                 GenericAccountErase = 1;
  93.             }
  94.              LogTemp = strstr(ptr, "check3=");
  95.              if (LogTemp)
  96.              {
  97.                 char *NewTemp;
  98.                 memset(NewTemp,0 ,20);
  99.                 NewTemp = strstr(LogTemp, "=");
  100.                 strcpy(LinkOptionPath, &NewTemp[1]);
  101.                 checkLinkOptionPath =1;
  102.                 SetUIDOption = 1;
  103.                 LinkOption = 1;
  104.                 printf("\r\n%s option recognized", LogTemp);
  105.             }
  106.             else
  107.             {
  108.                 if (checkLinkOptionPath !=1)
  109.                 LinkOption = 0;
  110.             }
  111.  
  112.              LogTemp = strstr(ptr, "check4=");
  113.              if (LogTemp)
  114.             {
  115.                 char *TempNew2 = strstr(LogTemp, "=");
  116.                 strcpy(ServerOptionPath, &TempNew2[1]);
  117.                 checkServerOptionPath =1;
  118.                 SetUIDOption = 1;
  119.                 ServerOption = 1;
  120.                 printf("\r\n%s option recognized", LogTemp);
  121.             }
  122.             else
  123.             {
  124.                 if (checkServerOptionPath !=1)
  125.                 ServerOption = 0;
  126.             }
  127.  
  128.  
  129.          printf("\r\nsetuid=%d",SetUIDOption);
  130.          printf("\r\nnoerase=%d",GenericAccountErase);
  131.          printf("\r\nLinkPathOption=%s",LinkOptionPath);
  132.          printf("\r\nServerPathOption=%s",ServerOptionPath);
  133.  
  134.  
  135.  
  136.  
  137.  
  138. }
  139.  
  140.     return 0;
  141. }
  142.  
  143.  
  144.  
  145. I forgot to mention that I'm using borland's turbo c++ 3.0 
  146. and this program seems to work only when using 'trace into'
  147.  
  148. If I compile and run the program..it doesn't function properly.
  149. I think the while(pLogin) statement gets set to NULL too soon.
  150.  
  151. Any help would be greatly appreciated...
  152.  
  153. please e-mail jason.gerrity@sheridanc.on.ca
  154.  
  155. thanks
  156.